﻿/**********************************************************
*-----------------------------------*
* flareJ JavaScript Library
*-----------------------------------*
* 作者:Joe_Sky
* 邮箱:hitomi_doax@tom.com
* 最后更新时间:2011-5-25
*-----*-----*-----*-----*-----*-----*
* 基于jQuery
***********************************************************/

/*----------------------------------------------*
* flareJ.Calendar
*-------*-------*-------*-------*-------*-------*
* 日历控件
*-------*-------*-------*-------*-------*-------*
* (必须)需引入flareJ.Base.js
* (可选)弹出日历控件需引入flareJ.Panel.js
*       和flareJ.ToolTip.js
*----------------------------------------------*/
(function ($) {
    var FJ = $.flareJ, flareJ = FJ;

    /************************************************************
    *-----------------------------------------------------------*
    *                         日历控件
    *-----------------------------------------------------------*
    *************************************************************
    *-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*
    * 本控件由caoailin的精美js日历修改而成,加入了
    * 填入某一个div元素中等功能
    *-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*
    * 调用方法:$("#div").CDRJ({param1:'1',param2:'2',...}).show();
    ************************************************************/
    this.CalendarJ = this.CDRJ = FJ.CalendarJ = FJ.CDRJ = FJ.CJ.extend({
        //#region 构造方法
        init: function (elemObj, settings) {
            //参数
            this._super(elemObj, $.extend(true, {
                fjType: "CDRJ",
                renderTo: elemObj,                          //要加载到的容器
                widthF: 370,                           //最大宽度
                heightF: 270,                          //最大高度
                hasImgBg: true,                            //是否使用图片背景
                hasMonthE: true,                           //是否显示英文月份
                showMoreDay: true,                         //是否显示上月和下月的日期
                dateFormat: 'yyyy-mm-dd',                  //日期格式
                dateInit: '2010-10-10',                    //初始日期
                clickDay: null,                            //点击日期事件
                dayColor: [],                              //日期颜色集合
                getDayColor: null,                         //获取日期颜色事件
                cbBindDate: null,                          //绑定日期完成事件
                borderWidth: 0,
                isShowWatermark: false,
                isShowToday: false,
                isShowSelectYear: false,
                fontFamily: "微软雅黑",  //方正综艺_GBK
                fontSizeMonth: 24,
                fontSizeMonthE: 18,
                fontSizeBody: 18,
                headPaddingH: 25,
                weekPaddingH: 50,
                bodyPaddingH: 50,
                headHeight: 70,
                colorParams: {                             //颜色参数
                    borderOut: "#A6C9E2",                  //外层边框
                    bgColor: "transparent",                //背景色
                    bgColor1: "#ffffff",                //背景渐变色开始
                    bgColor2: "#70C4F2",                //背景渐变色结束
                    headerBackColor: "transparent",        //表头背景颜色
                    headerFontColor: "#284F9A",            //表头字体颜色
                    menuOverColor: "#fdb721",              //菜单字体色
                    bodyBarBackColor: "transparent",       //日历标题背景色
                    bodyBarFontColor: "#4261A4",           //日历标题字体色
                    bodyFontColor: "#000000",              //日历字体色 
                    bodyHolidayFontColor: "#A12B5F",       //假日字体色
                    watermarkColor: "#d4d4d4",             //背景水印色
                    moreDayColor: "#f9f9f9"                //上月和下月日期的颜色
                }
            }, settings));

            this.date = null;       //当前日期
            this.timer = null;      //控制下拉菜单显示隐藏

            this.initFn();

            return this;
        },
        //#endregion

        //#region 初始化
        initFn: function () {
            this._super();
            this.create();
            this.show();
        },
        //#endregion

        //#region 构建
        create: function () {
            this._super();
            var thiz = this;

            //日历外层
            this.divOut.addClass("calendar").attr("id", "CalendarJ" + this.objId).attr("Author", "alin").attr("onselectstart", "return false").attr("oncontextmenu", "return false").css({
                height: FJ.isChrome ? thiz.p.heightF - 4 : thiz.p.heightF//,
                //width: "100%"
            });

            //背景
            if (this.p.hasImgBg || FJ.isOpera) {
                this.cdrBody = $('<table class="cdr_body"><tr><td class="cdr_body1"></td><td class="cdr_body2"></td><td class="cdr_body3"></td></tr><tr><td class="cdr_body4"></td><td class="cdr_body5"></td><td class="cdr_body6"></td></tr></table>');
                this.divOut.append(this.cdrBody);
            }
            else {
                this.divOut.addClass("cdr_bg").css({
                    border: "1px solid " + this.p.colorParams.borderOut,
                    background: (function(){
                        //设置渐变背景
                        if(FJ.isWebkit){
                            return "-webkit-gradient(linear, left top, left bottom , from("+thiz.p.colorParams.bgColor1+"), to("+thiz.p.colorParams.bgColor2+"))"
                        }
                        else if(FJ.isFF){
                            return "-moz-linear-gradient(top, "+thiz.p.colorParams.bgColor1+", "+thiz.p.colorParams.bgColor2+")";
                        }
                        else if(FJ.isIE){
                            thiz.divOut[0].style.filter = "alpha(opacity=100) progid:DXImageTransform.Microsoft.Gradient(GradientType=0, EndColorStr='" + thiz.p.colorParams.bgColor2 + "', StartColorStr='" + thiz.p.colorParams.bgColor1 + "')";
                            return "transparent";
                        }
                        else{
                            return "#fff";
                        }
                    })()
                });
            }

            this.cdrWmYear = $('<div class="divCvFd3" >2010</div>');
            this.cdrWatermark = ($('<div Author="alin" class="cdrWatermark divCvFd1" id="cdrWatermark"></div>').css({
                height: this.p.heightF + "px",
                color: this.p.colorParams.watermarkColor
            }).append($('<div class="divCvFd2"></div>').append(this.cdrWmYear)));
            if (!this.p.isShowWatermark) {
                this.cdrWatermark.hide();
            }
            this.cdrBodyOut = $('<div class="cdrBodyOut"></div>');

            //菜单
            this.cdrMenu = $('<div Author="alin" id="cdrMenu" style="position:absolute;left:0px;top:0px;z-index:3;display:none;" ></div>').hover(function () {
                thiz.showMenu(null, true);
            }, function () {
                thiz.hideMenu();
            });
            this.divOut.append(this.cdrWatermark).append(this.cdrBodyOut.append(this.getHeader()).append(this.getBodyBar()).append(this.getBody()).append(this.getBodyToday())).append(this.cdrMenu);

            //#region 设置样式
            this.cdrHeader.find("td").css({
                fontFamily: this.p.fontFamily,
                fontSize: this.p.fontSizeMonth + "px"
            });

            this.cdrHeader.find("td.currentMonthE").css((function () {
                var obj = { fontSize: thiz.p.fontSizeMonthE + "px" };
                if (FJ.isChrome) obj.textAlign = "left";
                return obj;
            })());

            this.divOut.find(".cdrBodyBar span,.cdrBodyBar td,.cdrBody td").css({
                fontFamily: this.p.fontFamily,
                fontSize: this.p.fontSizeBody + "px"
            });
            //#endregion

            //绑定初始日期
            this.bindDate(this.p.dateInit);

            return this;
        },
        //#endregion

        //#region 显示
        show: function () {
            this._super();
            return this;
        },
        //#endregion

        //#region 构建头部
        getHeader: function () {
            var thiz = this;

            this.cdrHeader = $('<table Author="alin" class="cdrHeader" cellSpacing="2" ></table>');
            this.cdrHeader.css({
                backgroundColor: this.p.colorParams.headerBackColor,
                width: (this.p.widthF - this.p.headPaddingH * 2) + "px",
                height: this.p.headHeight + "px",
                color: this.p.colorParams.headerFontColor
            });
            var tr_t = $('<tr Author="alin" align="center"></tr>');
            this.previousYear = $('<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" class="previousYear" title="上一年份" style="cursor:pointer;width:10px;" ><<</td>').bind("click", function () {
                thiz.onChangeYear(false);
            });
            this.previousMonth = $('<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" class="previousMonth" title="上一月份" style="cursor:pointer;width:10px;" ><img style="width:12px;height:21px;" src="' + FJ.CDRJ.imgFolderSrc + (FJ.isIE6 ? 'btn_l.gif' : 'btn_l.png') + '" /></td>').bind("click", function () {
                thiz.onChangeMonth(false);
            });
            this.currentYear = $('<td Author="alin" onmouseover="this.className=\'headerOver\'" class="currentYear" style="width:90px;cursor:pointer;" >0</td>').bind("click", function () {
                thiz.showMenu(true);
            }).bind("mouseout", function () {
                thiz.hideMenu();
                this.className = '';
            });
            this.currentMonth = $('<td Author="alin" onmouseover="this.className=\'headerOver\'" class="currentMonth" style="width:70px;cursor:pointer;" >0</td>').bind("click", function () {
                thiz.showMenu(false);
            }).bind("mouseout", function () {
                thiz.hideMenu();
                this.className = '';
            });
            this.currentMonthE = $('<td Author="alin" class="currentMonthE" style="width:100px;" >September</td>');
            this.nextMonth = $('<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" class="nextMonth" title="下一月份" style="cursor:pointer;width:10px;" ><img style="width:12px;height:21px;" src="' + FJ.CDRJ.imgFolderSrc + (FJ.isIE6 ? 'btn_r.gif' : 'btn_r.png') + '" /></td>').bind("click", function () {
                thiz.onChangeMonth(true);
            });
            this.nextYear = $('<td Author="alin" onmouseover="this.className=\'headerOver\'" onmouseout="this.className=\'\'" class="nextYear" title="下一年份" style="cursor:pointer;width:10px;" >>></td>').bind("click", function () {
                thiz.onChangeYear(true);
            });
            this.cdrHeader.append(tr_t.append(this.previousYear).append(this.previousMonth).append('<td></td>').append(this.currentYear).append(this.currentMonth).append((function(){
                if(thiz.p.hasMonthE){
                    return thiz.currentMonthE;
                }
                else{
                    return null;
                }
            })).append('<td></td>').append(this.nextMonth).append(this.nextYear));

            if (!this.p.isShowSelectYear) {
                this.previousYear.hide();
                this.nextYear.hide();
            }

            return this.cdrHeader;
        },
        //#endregion

        //#region 构建星期栏
        getBodyBar: function () {
            this.cdrBodyBar = $('<table Author="alin_bar" class="cdrBodyBar" cellSpacing="2" cellPadding="0"></table>');
            this.cdrBodyBar.css({
                backgroundColor: this.p.colorParams.bodyBarBackColor,
                color: this.p.colorParams.bodyBarFontColor,
                width: (this.p.widthF - this.p.weekPaddingH * 2) + "px"
            });
            var tr_t = $('<tr Author="alin_bar" align="center"></tr>');
            var day = new Array('<span style="color:' + this.p.colorParams.bodyHolidayFontColor + ';" >日</span>', '一', '二', '三', '四', '五', '<span style="color:' + this.p.colorParams.bodyHolidayFontColor + ';" >六</span>');
            for (i = 0; i < 7; i++) {
                tr_t.append('<td Author="alin_bar">' + day[i] + '</td>');
            }
            this.cdrBodyBar.append(tr_t);

            return this.cdrBodyBar;
        },
        //#endregion

        //#region 构建主体
        getBody: function () {
            var n = 0, oTr;
            this.cdrBody = $('<table Author="alin" class="cdrBody" cellSpacing="2" cellPadding="0"></table>');
            this.cdrBody.css({
                width: (this.p.widthF - this.p.bodyPaddingH * 2) + "px",
                height: (this.p.heightF - 112) + "px",
                color: this.p.colorParams.bodyFontColor
            });
            this.cdrDay = new Array(42);
            for (var i = 0; i < 6; i++) {
                oTr = $('<tr Author="alin" align="center"></tr>');
                for (var j = 0; j < 7; j++) {
                    this.cdrDay[n] = $('<td Author="alin" class="dayOut" id="cdrDay' + n + '" width="13%"></td>');
                    oTr.append(this.cdrDay[n]);
                    n++;
                }
                this.cdrBody.append(oTr);
            }

            return this.cdrBody;
        },
        //#endregion

        //#region 构建主体底部
        getBodyToday: function () {
            var thiz = this;

            this.cdrBodyToday = $('<table Author="alin" class="cdrBodyBar" style="" cellSpacing="2" cellPadding="0"></table>');
            if (!this.p.isShowToday) {
                this.cdrBodyToday.hide();
            }
            var tr_t2 = $('<tr align="center" Author="alin"></tr>');
            this.cdrTodayBtn = $('<td Author="alin" style="cursor:pointer;" >今天：' + new Date().toFormatString("yyyy年mm月dd日") + '</td>').bind("click", function () {
                thiz.getToday();
            });
            this.cdrBodyToday.append(tr_t2.append(this.cdrTodayBtn));

            return this.cdrBodyToday;
        },
        //#endregion

        //#region 显示菜单
        showMenu: function (isyear, isHover) {
            if (isyear != null) {

                var _obj = (isyear) ? this.currentYear : this.currentMonth;

                if (isyear) {
                    this.getYearMenu(this.date.getFullYear() - 5);
                }
                else {
                    this.getMonthMenu();
                }

                this.cdrMenu.css({
                    top: (_obj[0].offsetTop + _obj[0].offsetHeight - 20) + 'px',
                    left: (_obj[0].offsetLeft + this.p.headPaddingH) + 'px',
                    width: _obj[0].offsetWidth + 'px'
                });
            }

            if (this.timer != null)
                clearTimeout(this.timer);

            //是否渐变显示
            if (!isHover) {
                this.cdrMenu.stop().css({
                    opacity: 0
                }).show().animate({
                    opacity: 1
                }, 300);
            }
            else {
                this.cdrMenu.show();
            }
        },
        //#endregion

        //#region 隐藏菜单
        hideMenu: function () {
            var thiz = this;
            this.timer = window.setTimeout(function () {
                thiz.cdrMenu.stop().animate({
                    opacity: 0
                }, 300, function(){
                    thiz.cdrMenu.hide();
                });
            }, 500);
        },
        //#endregion

        //#region 构建年菜单
        getYearMenu: function (year) {
            var thiz = this;

            this.yearMenu = $('<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0"></table>');
            var str = '', oTr, oTd;
            for (i = 1; i <= 10; i++) {
                var _year = year + i;
                var _date = new Date(_year, this.date.getMonth(), this.date.getDate());

                oTr = $('<tr Author="alin" align="center"></tr>');
                str = '<td Author="alin" ';
                if (this.date.getFullYear() != _year) {
                    str += 'onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ';
                }
                else {
                    str += 'class="menuOver"';
                }
                str += '>' + _year + '年</td>';
                oTd = $(str);
                (function (date) {
                    oTd.bind("click", function () {
                        thiz.bindDate(date.toFormatString("-"));
                    });
                })(_date);
                this.yearMenu.append(oTr.append(oTd));
            }

            //#region 增加、减少年数按钮
            var tr_t1 = $('<tr Author="alin" align="center"></tr>');
            var td_t1 = $('<td Author="alin"></td>');
            var tab_t2 = $('<table Author="alin" style="font-size:12px;width:100%;" cellSpacing="0" cellPadding="0"></table>');
            var tr_t2 = $('<tr Author="alin" align="center"></tr>');
            this.btnSubYear = $('<td Author="alin" style="height:20px;" onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ><<</td>').bind("click", function () {
                thiz.getYearMenu(year - 10);
            });
            this.btnAddYear = $('<td Author="alin" onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" >>></td>').bind("click", function () {
                thiz.getYearMenu(year + 10);
            });
            //#endregion

            this.yearMenu.append(tr_t1.append(td_t1.append(tab_t2.append(tr_t2.append(this.btnSubYear).append(this.btnAddYear)))));
            this.cdrMenu.html(this.yearMenu);
        },
        //#endregion

        //#region 构建月菜单
        getMonthMenu: function () {
            var thiz = this;

            this.monthMenu = $('<table Author="alin" cellSpacing="0" class="cdrMenu" cellPadding="0"></table>');
            var str = '', oTr, oTd;
            for (i = 1; i <= 12; i++) {
                var _day = this.date.getDate();
                //如果月份为2月,设定日期不超过28号
                if (i == 2) {
                    _day = 28;
                }
                var _date = new Date(this.date.getFullYear(), i - 1, _day);

                oTr = $('<tr Author="alin" align="center"></tr>');
                str = '<td Author="alin" ';
                if (this.date.getMonth() + 1 != i) {
                    str += 'onmouseover="this.className=\'menuOver\'" onmouseout="this.className=\'\'" ';
                }
                else {
                    str += 'class="menuOver"';
                }
                str += '>' + i + '月</td>';
                oTd = $(str);
                (function (date) {
                    oTd.bind("click", function () {
                        thiz.bindDate(date.toFormatString("-"));
                    });
                })(_date);
                this.monthMenu.append(oTr.append(oTd));
            }

            this.cdrMenu.html(this.monthMenu);
        },
        //#endregion

        //#region 年改变事件
        onChangeYear: function (isnext) {
            var _year = this.date.getFullYear();
            var _month = this.date.getMonth() + 1;
            var _date = this.date.getDate();

            if (_year > 999 && _year < 10000) {
                if (isnext) {
                    _year++;
                }
                else {
                    _year--;
                }
            }
            else {
                alert("年份超出范围（1000-9999）!");
            }
            this.bindDate(_year + '-' + _month + '-' + _date);
        },
        //#endregion

        //#region 月改变事件
        onChangeMonth: function (isnext) {
            var _year = this.date.getFullYear();
            var _month = this.date.getMonth() + 1;
            var _date = this.date.getDate();

            if (isnext) {
                _month++;
            }
            else {
                _month--;
            }

            if (_year > 999 && _year < 10000) {
                if (_month < 1) {
                    _month = 12;
                    _year--;
                }
                if (_month > 12) {
                    _month = 1;
                    _year++;
                }
            }
            else {
                alert("年份超出范围（1000-9999）!");
            }

            //如果月份为2月,设定日期不超过28号
            if (_month == 2) {
                _date = 28;
            }

            this.bindDate(_year + '-' + _month + '-' + _date);
        },
        //#endregion

        //#region 绑定日期数据
        bindDate: function (date) {
            var thiz = this;

            //获取日期颜色事件
            if (this.p.getDayColor != null) {
                this.p.getDayColor.call(this, date);
            }

            var _monthDays = new Array(31, 30, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
            var _arr = date.replace(/[^\d]/ig, '-').replace(/^\-|\-$/ig, '').split('-');
            //alert(date.replace(/[^\d]/ig,'-').replace(/^\-|\-$/ig,''));
            var _date = new Date(_arr[0], _arr[1] - 1, _arr[2]);
            if (isNaN(_date))
                _date = new Date();
            this.date = _date;
            this.bindHeader();

            var _year = _date.getFullYear();
            var _month = _date.getMonth();
            var _day = 1;

            var _startDay = new Date(_year, _month, 1).getDay();
            var _previYear = _month == 0 ? _year - 1 : _year;
            var _previMonth = _month == 0 ? 11 : _month - 1;
            var _previDay = _monthDays[_previMonth];
            if (_previMonth == 1)
                _previDay = ((_previYear % 4 == 0) && (_previYear % 100 != 0) || (_previYear % 400 == 0)) ? 29 : 28;
            _previDay -= _startDay - 1;
            var _nextDay = 1;

            _monthDays[1] = ((_year % 4 == 0) && (_year % 100 != 0) || (_year % 400 == 0)) ? 29 : 28;

            for (i = 0; i < 40; i++) {
                var _dayElement = this.cdrDay[i];

                //去除颜色
                _dayElement.css({
                    border: "0",
                    backgroundColor: "transparent"
                }).removeClass("hasColor_" + this.objId).attr("date", "");

                _dayElement.unbind("mouseover").bind("mouseover", function () {
                    thiz.onMouseOver(this);
                }).unbind("mouseout").bind("mouseout", function () {
                    thiz.onMouseOut(this);
                }).unbind("click").bind("click", function () {
                    thiz.onClick(this);
                });

                this.onMouseOut(_dayElement[0]);
                _dayElement.css("color", "");

                if (i < _startDay) {
                    //获取上一个月的日期
                    if (this.p.showMoreDay) {
                        var _previDate = new Date(_year, _month - 1, _previDay);
                        _dayElement.html(_previDay);
                        _dayElement.attr("title", _previDate.toFormatString("yyyy年mm月dd日"));
                        _dayElement.attr("value", _previDate.toFormatString(this.p.dateFormat));
                        _dayElement.css("color", this.p.colorParams.moreDayColor);

                        _previDay++;
                    }
                    else {
                        _dayElement.html("");
                        _dayElement.attr("title", "");
                    }
                }
                else
                    if (_day > _monthDays[_month]) {
                        //获取下个月的日期
                        if (this.p.showMoreDay) {
                            var _nextDate = new Date(_year, _month + 1, _nextDay);
                            _dayElement.html(_nextDay);
                            _dayElement.attr("title", _nextDate.toFormatString("yyyy年mm月dd日"));
                            _dayElement.attr("value", _nextDate.toFormatString(this.p.dateFormat));
                            _dayElement.css("color", this.p.colorParams.moreDayColor);

                            _nextDay++;
                        }
                        else {
                            _dayElement.html("");
                            _dayElement.attr("title", "");
                        }
                    }
                    else
                        if (i >= new Date(_year, _month, 1).getDay() && _day <= _monthDays[_month]) {
                            //获取本月日期
                            _dayElement.html(_day);

                            if (_day == _date.getDate()) {
                                //this.onMouseOver(_dayElement[0]);
                                //_dayElement.unbind("mouseover mouseout");
                            }

                            if (this.isHoliday(_year, _month, _day)) {
                                _dayElement.css("color", this.p.colorParams.bodyHolidayFontColor);
                            }
                            var _curDate = new Date(_year, _month, _day);
                            _dayElement.attr("title", _curDate.toFormatString("yyyy年mm月dd日"));
                            _dayElement.attr("value", _curDate.toFormatString(this.p.dateFormat));

                            //设置日期颜色
                            for (var j = 0; j < this.p.dayColor.length; j++) {
                                if (this.p.dayColor[j].day == _day) {
                                    _dayElement.css({
                                        border: "1px solid #868686",
                                        backgroundColor: this.p.dayColor[j].color
                                    }).addClass("hasColor_" + this.objId).attr("date", _curDate);
                                    break;
                                }
                            }

                            _day++;
                        }
                        else {
                            _dayElement.html("");
                            _dayElement.attr("title", "");
                        }
            }

            this.cdrMenu.hide();

            //清空日期颜色集合
            this.p.dayColor = [];

            //绑定日期完成事件
            if (this.p.cbBindDate != null) {
                this.p.cbBindDate.call(this, date);
            }
        },
        //#endregion

        //#region 绑定头部数据
        bindHeader: function () {
            this.currentYear.text(this.date.toFormatString("yyyy年"));
            var month = this.date.toFormatString("mm", true);
            this.currentMonth.text(month + "月");
            this.cdrWmYear.text(this.date.getFullYear());

            if(this.p.hasMonthE){
                //设置英文月份
                switch (month) {
                    case "1":
                        this.currentMonthE.text("January");
                        break;
                    case "2":
                        this.currentMonthE.text("February");
                        break;
                    case "3":
                        this.currentMonthE.text("March");
                        break;
                    case "4":
                        this.currentMonthE.text("April");
                        break;
                    case "5":
                        this.currentMonthE.text("May");
                        break;
                    case "6":
                        this.currentMonthE.text("June");
                        break;
                    case "7":
                        this.currentMonthE.text("July");
                        break;
                    case "8":
                        this.currentMonthE.text("August");
                        break;
                    case "9":
                        this.currentMonthE.text("September");
                        break;
                    case "10":
                        this.currentMonthE.text("October");
                        break;
                    case "11":
                        this.currentMonthE.text("November");
                        break;
                    case "12":
                        this.currentMonthE.text("December");
                        break;
                }
            }
        },
        //#endregion

        //#region 点击日期事件
        onClick: function (obj) {
            if (obj.innerHTML != "") {
                if (this.p.clickDay != null) {
                    this.p.clickDay.call(this, $(obj).attr("value"));
                }
            }
        },
        //#endregion

        //#region 通用方法
        getToday: function () {
            var _date = new Date();
            this.bindDate(_date.toFormatString("-"));
        },

        isHoliday: function (year, month, date) {
            var _date = new Date(year, month, date);
            return (_date.getDay() == 6 || _date.getDay() == 0);
        },

        onMouseOver: function (obj) {
            //obj.className = "dayOver";
        },

        onMouseOut: function (obj) {
            //obj.className = "dayOut";
        }
        //#endregion
    });

    //#region 静态调用方法
    FJ.CDRJ.show = function (settings) {
        return new FJ.CDRJ($("body"), settings).show();
    };
    //#endregion

    //#region 绑定到jquery
    $.fn.extend({
        CalendarJ: function (settings) {
            return new FJ.CalendarJ(this, settings);
        },
        CDRJ: function (settings) {
            return $(this).CalendarJ(settings);
        }
    });
    //#endregion

    //#region 图片文件夹路径
    FJ.CDRJ.imgFolderSrc = FJ.imgPath + "Calendar/";
    //#endregion

    //#region 加载css
    $("head").append('<link id="CalendarJStyle" href="' + FJ.cssPath + 'flareJ.Calendar.css" rel="stylesheet" type="text/css" />');
    //#endregion

    /************************************************************
    *-----------------------------------------------------------*
    *                       弹出日历控件
    *-----------------------------------------------------------*
    *************************************************************
    *-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*
    * 
    *-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*
    * 调用方法:$("#div").DPJ();
    ************************************************************/
    if (typeof FJ.TTJ != "undefined") {
        this.DatePickerJ = this.DPJ = FJ.DatePickerJ = FJ.DPJ = FJ.TTJ.extend({
            //#region 构造方法
            init: function (elemObj, settings) {
                var thiz = this;

                //参数
                this._super(elemObj, $.extend(true, {
                    fjType: "DPJ",
                    borderWidth: 0,
                    widthF: 360,                           //最大宽度
                    heightF: 270,                          //最大高度
                    dateFormat: 'yyyy-mm-dd',                  //日期格式
                    dateInit: new Date().toFormatString("yyyy-mm-dd"),
                    divType: "hover",
                    hoverDirect: "bottom",
                    shiftLeft: 10,
                    shiftTop: 20,
                    urlType: "html",
                    hoverName: "hoverDpj",
                    hoverType: "focus",
                    onlyFirstLoad: true,
                    isAsync: false,
                    speed: 1,
                    loadHTML: function (param) {
                        this.cdrj.divOut.show();
                        return this.cdrj.divOut;
                    },
                    clickDay: function (date) {
                        this.hdj.currentObj.val(date);
                        this.hdj.closeByFocus = true;
                        //elemObj.val(date);
                        //点击后关闭
                        this.hdj.st.hoverSpeed = 0;
                        this.hdj.close($("#" + this.hdj.hoverId));
                        this.hdj.st.hoverSpeed = 777;
                    },
                    colorParams: {                             //颜色参数
                        bgColorBody: "transparent",
                        bgColor: "transparent",
                        borderOut: "#A6C9E2"
                    }
                }, settings));

                //内容页不显示滚动条
                this.bodyIn.css({
                    overflowX: "hidden",
                    overflowY: "hidden"
                });

                //日历控件对象
                this.cdrj = FJ.CDRJ.show({
                    hasImgBg: this.p.hasImgBg,
                    hasMonthE: this.p.hasMonthE,
                    isShowSelectYear: this.p.isShowSelectYear,
                    dateFormat: this.p.dateFormat,
                    dateInit: this.p.dateInit,
                    fontFamily: this.p.fontFamily,
                    fontSizeMonth: this.p.fontSizeMonth,
                    fontSizeMonthE: this.p.fontSizeMonthE,
                    fontSizeBody: this.p.fontSizeBody,
                    headPaddingH: this.p.headPaddingH,
                    weekPaddingH: this.p.weekPaddingH,
                    bodyPaddingH: this.p.bodyPaddingH,
                    widthF: this.p.widthF - 2,                           //最大宽度
                    heightF: this.p.heightF - 2,                     //最大高度
                    clickDay: this.p.clickDay,
                    colorParams: this.p.colorParams
                });
                this.cdrj.divOut.hide();

                this.cdrj.hdj = this;

                return this;
            }
            //#endregion
        });

        //#region 绑定到jquery
        $.fn.extend({
            DatePickerJ: function (settings) {
                //返回悬停层对象
                return new DatePickerJ(this, settings);
            },
            DPJ: function (settings) {
                return $(this).DatePickerJ(settings);
            }
        });
        //#endregion
    }
})(jQuery);